<div class="full_w">
    <div class="h_title"><?php echo Yii::t('AdmincpModule.admincp', 'Categories'); ?></div>
    <h2>Categories</h2>
    <p>Categories provide a helpful way to group related posts together, and to quickly tell readers what a post is about. Categories also make it easier for people to find your content. Categories are similar to, but broader than tags</p>
    <div class="entry">
        <div class="sep"></div>
    </div>
    <table class="ui-sortable">
        <thead>
            <tr>
            	<th scope="col" class="chb"><input type="checkbox" onclick="selectAll(this);"></th>
                <th scope="col"><?php  echo Yii::t('AdmincpModule.admincp', 'Name');?></th>
                <th scope="col"><?php  echo Yii::t('AdmincpModule.admincp', 'Description');?></th>
                <th scope="col"><?php  echo Yii::t('AdmincpModule.admincp', 'Code');?></th>
                <th scope="col"><?php  echo Yii::t('AdmincpModule.admincp', 'Order');?></th>
                <th scope="col"><?php  echo Yii::t('AdmincpModule.admincp', 'Status');?></th>

                <th scope="col" style="width: 65px;"><?php  echo Yii::t('AdmincpModule.admincp', 'Options');?></th>
            </tr>
        </thead>
            
        <tbody>
        
        <?php if(!empty($arrCategories)):?>
			<?php foreach($arrCategories as $i=>$R):?>
            <tr class="ui-state-highlight1 level-<?php echo $R['category_level']; ?>">
                <td class="align-center"><input type="checkbox" name="id[]" value="" <?php if($R['category_num_children'] > 0): ?>disabled="disabled"<?php endif; ?>></td>
                <td>
                    <?php if($R['category_level'] > 0): for($i=0; $i<$R['category_level']; $i++): echo '&nbsp;&nbsp;&nbsp;&nbsp;'; endfor; echo '|---'; endif; ?>
                    <strong><a href="javascript:void(0);" style="text-decoration:none;"><?php echo $R['category_name']; ?></a></strong>
                </td>
                <td><?php echo $R['category_description']; ?></td>
                <td><?php echo $R['category_code']; ?></td>
                <td>
					<?php if(isset($R['category_id_prev'])):?><a href="javascript:void(0);" class="icon icon-bullet_arrow_up" onclick="swap('<?php echo $R['category_id_prev']; ?>','<?php echo $R['category_id']; ?>');">^</a><?php endif; ?>
                	<?php if(isset($R['category_id_next'])):?><a href="javascript:void(0);" class="icon icon-bullet_arrow_up" onclick="swap('<?php echo $R['category_id_next']; ?>','<?php echo $R['category_id']; ?>');">v</a><?php endif; ?>
                </td>
                <td><?php echo $R['category_status']; ?></td>
                <td>
                	<a href="<?php echo LINK_ADMINCP_CATEGORIES.'/form/?id='.$R['category_id']; ?>"  title="Edit">Edit</a> | 
                    <?php if($R['category_num_children'] > 0): ?>
                    <span style="color:#999">Delete</span>
                    <?php else: ?>
                    <a href="<?php echo LINK_ADMINCP_CATEGORIES.'/delete/?id='.$R['category_id']; ?>" title="Delete">Delete</a>
                    <?php endif; ?>
                </td>
            </tr>
            <?php endforeach; ?>
		<?php else: ?>
            <tr>
                <td colspan="6">No data found!</td>
            </tr>
        <?php endif; ?>
        
        </tbody>
    </table>
    <div class="entry">
        <div class="sep"></div>		
        <a class="button add" href="<?php echo LINK_ADMINCP_CATEGORIES.'/form'; ?>"><?php echo Yii::t('AdmincpModule.admincp', 'Add Category'); ?></a> <a class="button" href="">Categories</a> 
    </div>
</div>
 <style>
.ui-state-highlight { height: 1.5em; line-height: 1.2em; border:#666 2px solid; border-style: dashed; margin: 20px 0;}
.ui-state-highlight td{ background:none repeat scroll 0 0 #FFF8CF;}
</style>
<script>
$(function() {
	$('td, th', '.ui-sortable').each(function () {
		$(this).css("width", $(this).width());
	});
	$( ".ui-sortable tbody" ).sortable({
		placeholder: "ui-state-highlight",
		connectWith: ".level-0"//$(this).id
	}).disableSelection();
});
function swap(id1, id2){
	var url = '/admincp/categories/swap';
	$.ajax({
		type: 'POST',
		url: url,
		data: {id1: id1, id2: id2},
		dataType: 'json',
		success: function(data){
			if(data.result==2) location.reload(true);
			else alert(data.msg);
		}
	});						
}
</script>